home *** CD-ROM | disk | FTP | other *** search
/ AmigActive 10 / AACD 10.iso / AACD / Games / MAME / src / vidhrdw / milliped.c < prev    next >
C/C++ Source or Header  |  2000-04-04  |  4KB  |  178 lines

  1. /***************************************************************************
  2.  
  3.   vidhrdw.c
  4.  
  5.   Functions to emulate the video hardware of the machine.
  6.  
  7. ***************************************************************************/
  8.  
  9. #include "driver.h"
  10. #include "vidhrdw/generic.h"
  11.  
  12.  
  13.  
  14. static struct rectangle spritevisiblearea =
  15. {
  16.     1*8, 31*8-1,
  17.     0*8, 30*8-1
  18. };
  19.  
  20.  
  21.  
  22. /***************************************************************************
  23.  
  24.   Millipede doesn't have a color PROM, it uses RAM.
  25.   The RAM seems to be conncted to the video output this way:
  26.  
  27.   bit 7 red
  28.         red
  29.         red
  30.         green
  31.         green
  32.         blue
  33.         blue
  34.   bit 0 blue
  35.  
  36. ***************************************************************************/
  37. WRITE_HANDLER( milliped_paletteram_w )
  38. {
  39.     int bit0,bit1,bit2;
  40.     int r,g,b;
  41.  
  42.  
  43.     paletteram[offset] = data;
  44.  
  45.     /* red component */
  46.     bit0 = (~data >> 5) & 0x01;
  47.     bit1 = (~data >> 6) & 0x01;
  48.     bit2 = (~data >> 7) & 0x01;
  49.     r = 0x21 * bit0 + 0x47 * bit1 + 0x97 * bit2;
  50.  
  51.     /* green component */
  52.     bit0 = 0;
  53.     bit1 = (~data >> 3) & 0x01;
  54.     bit2 = (~data >> 4) & 0x01;
  55.     g = 0x21 * bit0 + 0x47 * bit1 + 0x97 * bit2;
  56.  
  57.     /* blue component */
  58.     bit0 = (~data >> 0) & 0x01;
  59.     bit1 = (~data >> 1) & 0x01;
  60.     bit2 = (~data >> 2) & 0x01;
  61.     b = 0x21 * bit0 + 0x47 * bit1 + 0x97 * bit2;
  62.  
  63.     palette_change_color(offset,r,g,b);
  64. }
  65.  
  66.  
  67.  
  68. /***************************************************************************
  69.  
  70.   Draw the game screen in the given osd_bitmap.
  71.   Do NOT call osd_update_display() from this function, it will be called by
  72.   the main emulation engine.
  73.  
  74. ***************************************************************************/
  75. void milliped_vh_screenrefresh(struct osd_bitmap *bitmap,int full_refresh)
  76. {
  77.     int offs;
  78.  
  79.  
  80.     if (palette_recalc() || full_refresh)
  81.         memset (dirtybuffer, 1, videoram_size);
  82.  
  83.     /* for every character in the Video RAM, check if it has been modified */
  84.     /* since last time and update it accordingly. */
  85.     for (offs = videoram_size - 1;offs >= 0;offs--)
  86.     {
  87.         if (dirtybuffer[offs])
  88.         {
  89.             int sx,sy;
  90.             int bank;
  91.             int color;
  92.  
  93.  
  94.             dirtybuffer[offs] = 0;
  95.  
  96.             sx = offs % 32;
  97.             sy = offs / 32;
  98.  
  99.             if (videoram[offs] & 0x40)
  100.                 bank = 1;
  101.             else bank = 0;
  102.  
  103.             if (videoram[offs] & 0x80)
  104.                 color = 2;
  105.             else color = 0;
  106.  
  107.             drawgfx(bitmap,Machine->gfx[0],
  108.                     0x40 + (videoram[offs] & 0x3f) + 0x80 * bank,
  109.                     bank + color,
  110.                     0,0,
  111.                     8*sx,8*sy,
  112.                     &Machine->drv->visible_area,TRANSPARENCY_NONE,0);
  113.         }
  114.     }
  115.  
  116.  
  117.     /* Draw the sprites */
  118.     for (offs = 0;offs < 0x10;offs++)
  119.     {
  120.         int spritenum,color;
  121.         int x, y;
  122.         int sx, sy;
  123.  
  124.  
  125.         x = spriteram[offs + 0x20];
  126.         y = 240 - spriteram[offs + 0x10];
  127.  
  128.         spritenum = spriteram[offs] & 0x3f;
  129.         if (spritenum & 1) spritenum = spritenum / 2 + 64;
  130.         else spritenum = spritenum / 2;
  131.  
  132.         /* Millipede is unusual because the sprite color code specifies the */
  133.         /* colors to use one by one, instead of a combination code. */
  134.         /* bit 7-6 = palette bank (there are 4 groups of 4 colors) */
  135.         /* bit 5-4 = color to use for pen 11 */
  136.         /* bit 3-2 = color to use for pen 10 */
  137.         /* bit 1-0 = color to use for pen 01 */
  138.         /* pen 00 is transparent */
  139.         color = spriteram[offs + 0x30];
  140.         Machine->gfx[1]->colortable[3] =
  141.                 Machine->pens[16+((color >> 4) & 3)+4*((color >> 6) & 3)];
  142.         Machine->gfx[1]->colortable[2] =
  143.                 Machine->pens[16+((color >> 2) & 3)+4*((color >> 6) & 3)];
  144.         Machine->gfx[1]->colortable[1] =
  145.                 Machine->pens[16+((color >> 0) & 3)+4*((color >> 6) & 3)];
  146.  
  147.         drawgfx(bitmap,Machine->gfx[1],
  148.                 spritenum,
  149.                 0,
  150.                 0,spriteram[offs] & 0x80,
  151.                 x,y,
  152.                 &spritevisiblearea,TRANSPARENCY_PEN,0);
  153.  
  154.         /* mark tiles underneath as dirty */
  155.         sx = x >> 3;
  156.         sy = y >> 3;
  157.  
  158.         {
  159.             int max_x = 1;
  160.             int max_y = 2;
  161.             int x2, y2;
  162.  
  163.             if (x & 0x07) max_x ++;
  164.             if (y & 0x0f) max_y ++;
  165.  
  166.             for (y2 = sy; y2 < sy + max_y; y2 ++)
  167.             {
  168.                 for (x2 = sx; x2 < sx + max_x; x2 ++)
  169.                 {
  170.                     if ((x2 < 32) && (y2 < 32) && (x2 >= 0) && (y2 >= 0))
  171.                         dirtybuffer[x2 + 32*y2] = 1;
  172.                 }
  173.             }
  174.         }
  175.  
  176.     }
  177. }
  178.